package my.jwds.p108;

import my.jwds.p94.TreeNode;

public class SortedArrayToBST {

    public static void main(String[] args) {

        SortedArrayToBST obj = new SortedArrayToBST();
        long start = System.currentTimeMillis();
        System.out.println("运行时间:" + (System.currentTimeMillis() - start));
    }




    public TreeNode sortedArrayToBST(int[] nums) {
        return dfs(nums,0, nums.length-1);
    }


    TreeNode dfs(int[]nums,int lower,int upper){
        if (lower > upper)return null;
        int mid = (lower + upper)/2;
        TreeNode node = new TreeNode(nums[mid]);
        node.left = dfs(nums,lower,mid-1);
        node.right = dfs(nums,mid+1,upper);
        return node
                ;
    }

}